package com.practise.demo;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/calc")
public class CalcController {
    @RequestMapping("/sum")
    public String sum(Integer num1,Integer num2){
        // 参数名需要与前端的input框的name保持一致
        if(num1 == null || num2 == null){
            return "输入错误，请核对";
        }
        Integer sum = num1 + num2;
        return "<h1>计算结果为：" + sum + "</h1>";
    }

    @RequestMapping("/sub")
    public String sub(Integer num1,Integer num2){
        // 参数名需要与前端的input框的name保持一致
        if(num1 == null || num2 == null){
            return "输入错误，请核对";
        }
        Integer sum = num1 - num2;
        return "<h1>计算结果为：" + sum + "</h1>";
    }

    @RequestMapping("/multiply")
    public String multiply(Integer num1,Integer num2){
        // 参数名需要与前端的input框的name保持一致
        if(num1 == null || num2 == null){
            return "输入错误，请核对";
        }
        Integer sum = num1 * num2;
        return "<h1>计算结果为：" + sum + "</h1>";
    }

    @RequestMapping("/div")
    public String div(Double num1,Double num2){
        // 参数名需要与前端的input框的name保持一致
        if(num1 == null || num2 == null){
            return "输入错误，请核对";
        }
        Double sum = num1 / num2;
        return "<h1>计算结果为：" + sum + "</h1>";
    }
}
